home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / music / eked-m1.zoo / src / listwin.c < prev    next >
C/C++ Source or Header  |  1995-02-19  |  6KB  |  231 lines

  1. /*
  2.  *  EKED-M1 : Editor for Korg M1 synth; listwin.c : list windows
  3.  *  Copyright (C) 1995 Steven M. Eker (Steven.Eker@brunel.ac.uk)
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <stddef.h>
  21. #include <gemfast.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24. #include "gm/gem_man.h"
  25. #include "eked-m1.h"
  26. #include "defs.h"
  27. #include "types.h"
  28. #include "externs.h"
  29.  
  30. #define ROWS        20
  31.  
  32. typedef struct {
  33.   LW_TYPE type;
  34.   char title[24];
  35.   int selected;
  36.   int dest;
  37.   BANK *bank;
  38. } LIST_WINDOW;
  39.  
  40. typedef struct {
  41.   DRAG_TYPE drag_type;
  42.   int bank_nr;
  43.   int item_nr;
  44. } DRAG_ITEM;
  45.  
  46. static int point_size = 8;
  47.  
  48. static char *content(int x, int y, long usr_val);
  49. static int action(int handle, E_TYPE type, void *event,
  50.                   int x_pos, int y_pos, long usr_val);
  51.  
  52. void ls_size(int size)
  53. {
  54.   point_size = size;
  55. }
  56.  
  57. void ls_window(LW_TYPE type, BANK *bank)
  58. {
  59.   LIST_WINDOW *p = MALLOC(LIST_WINDOW);
  60.   int t;
  61.   
  62.   if(p == NULL){
  63.     fm_alert(1, WINDMEM_ALERT);
  64.     return;
  65.   }
  66.   p->type = type;
  67.   strcpy(p->title, type == COMB_LIST ? "Bank 0 Combinations" : 
  68.          "Bank 0 Programs");
  69.   p->title[5] = '0' + bank->bank_nr;
  70.   p->selected = NIL;
  71.   p->dest = NIL;
  72.   p->bank = bank;
  73.   t = lm_open((GRECT *) NULL, p->title,
  74.               5, ROWS, point_size, 1 + point_size / 4,
  75.               13, point_size, WHITE, type == COMB_LIST ? RED : BLUE,
  76.               &content, &action, (long) p);
  77.   if(t < 0){
  78.     FREE(p);
  79.     fm_alert(1, t == OUT_OF_MEMORY ? WINDMEM_ALERT : WINDOW_ALERT);
  80.     return;
  81.   }
  82.   if(type == COMB_LIST)
  83.     bank->comb_win = t;
  84.   else
  85.     bank->prog_win = t;
  86. }
  87.  
  88. static char *content(int x, int y, long usr_val)
  89. {
  90.   LIST_WINDOW *p = (LIST_WINDOW *) usr_val;
  91.   int n = ROWS * x + y;
  92.   BYTE *base;
  93.   static char text[15];
  94.  
  95.   text[0] = (n == p->selected || n == p->dest);
  96.   text[1] = '0' + n / 10;
  97.   text[2] = '0' + n % 10;
  98.   text[3] = ' ';
  99.   base = (p->type == COMB_LIST) ? COMB_DATA(p->bank, n) : PROG_DATA(p->bank, n);
  100.   (void) korg2str(text + 4, base, (size_t) 10);
  101.   return text;
  102. }
  103.  
  104. static int action(int handle, E_TYPE type, void *event,
  105.                   int x_pos, int y_pos, long usr_val)
  106. {
  107.   LIST_WINDOW *p = (LIST_WINDOW *) usr_val;
  108.   int n, t;
  109.   CLICK *c;
  110.   DRAG_DROP *d;
  111.   DRAG_ITEM drag_item, *di;
  112.   BYTE *item;
  113.  
  114.   switch(type){
  115.   case E_CLEANUP:
  116.     m1_ctrl(handle, EXITING, 0, 0, (BYTE *) NULL);
  117.     if(p->type == COMB_LIST)
  118.       p->bank->comb_win = 0;
  119.     else
  120.       p->bank->prog_win = 0;
  121.     FREE(p);
  122.     break;
  123.   case E_USER:
  124.     switch(((int *) event)[0]){
  125.     case M1_CTRL_LOST:
  126.       t = p->selected;
  127.       if(t != NIL){
  128.         p->selected = NIL;
  129.         lm_update(handle, t / ROWS, t % ROWS);
  130.       }
  131.       break;
  132.     case UPDATE_ITEM:
  133.       t = ((int *) event)[1];
  134.       lm_update(handle, t / ROWS, t % ROWS);
  135.       break;
  136.     }
  137.     break;
  138.   case E_CLICK:
  139.     c = (CLICK *) event;
  140.     n = ROWS * c->m_x + c->m_y;
  141.     t = p->selected;
  142.     if(n != t){
  143.       p->selected = n;
  144.       if(t != NIL)
  145.         lm_update(handle, t / ROWS, t % ROWS);
  146.       lm_update(handle, n / ROWS, n % ROWS);
  147.     }
  148.     if(p->type == COMB_LIST){
  149.       item = COMB_DATA(p->bank, n);
  150.       item[10] = 4;    /* convert to a MULTI (if not already) */
  151.       m1_ctrl(handle, FORCE_NR | FORCE_DATA, COMB_MODE, n, item);
  152.       if(c->n_clks == 2)
  153.         ce_window(p->bank, n);
  154.       else{
  155.         drag_item.drag_type = DRAG_COMB;
  156.         drag_item.bank_nr = p->bank->bank_nr;
  157.         drag_item.item_nr = n;
  158.         lm_dragbox(handle, n / ROWS, n % ROWS, (long) &drag_item);
  159.       }
  160.     }
  161.     else{
  162.       item = PROG_DATA(p->bank, n);
  163.       m1_ctrl(handle, FORCE_NR | FORCE_DATA, PROG_MODE, n, item);
  164.       if(c->n_clks == 2)
  165.         pe_window(p->bank, n);
  166.       else{
  167.         drag_item.drag_type = DRAG_PROG;
  168.         drag_item.bank_nr = p->bank->bank_nr;
  169.         drag_item.item_nr = n;
  170.         lm_dragbox(handle, n / ROWS, n % ROWS, (long) &drag_item);
  171.       }
  172.     }
  173.     break;
  174.   case E_DRAG:
  175.     d = (DRAG_DROP *) event;
  176.     di = (DRAG_ITEM *) d->object;
  177.     if(di->drag_type == DRAG_COMB || di->drag_type == DRAG_PROG){
  178.       n = ROWS * d->m_x + d->m_y;
  179.       t = p->dest;
  180.       if(n != t){
  181.         p->dest = n;
  182.         if(t != NIL && t != p->selected)
  183.           lm_update(handle, t / ROWS, t % ROWS);
  184.         if(n != p->selected)
  185.           lm_update(handle, n / ROWS, n % ROWS);
  186.       }
  187.     }
  188.     break;
  189.   case E_DROP:
  190.     d = (DRAG_DROP *) event;
  191.     di = (DRAG_ITEM *) d->object;
  192.     if(di->drag_type == DRAG_COMB || di->drag_type == DRAG_PROG){
  193.       t = p->dest;
  194.       if(t != NIL){
  195.         n= p->bank->bank_nr;
  196.         if(p->type == COMB_LIST){
  197.           if(di->drag_type == DRAG_COMB){
  198.             if(di->bank_nr != n || di->item_nr != t)
  199.               ic_combcopy(n, t, di->bank_nr, di->item_nr);
  200.           }
  201.           else if(di->drag_type == DRAG_PROG)
  202.             ic_peffcopy(n, t, di->bank_nr, di->item_nr);
  203.         }
  204.         else{
  205.           if(di->drag_type == DRAG_PROG){
  206.             if(di->bank_nr != n || di->item_nr != t)
  207.               ic_progcopy(n, t, di->bank_nr, di->item_nr);
  208.           }
  209.           else if(di->drag_type == DRAG_COMB)
  210.             ic_ceffcopy(n, t, di->bank_nr, di->item_nr);
  211.         }
  212.       }
  213.       p->dest = NIL;
  214.       if(t != NIL && t != p->selected)
  215.         lm_update(handle, t / ROWS, t % ROWS);
  216.     }
  217.     break;
  218.   case E_DRAGEXIT:
  219.     d = (DRAG_DROP *) event;
  220.     di = (DRAG_ITEM *) d->object;
  221.     if(di->drag_type == DRAG_COMB || di->drag_type == DRAG_PROG){
  222.       t = p->dest;
  223.       p->dest = NIL;
  224.       if(t != NIL && t != p->selected)
  225.         lm_update(handle, t / ROWS, t % ROWS);
  226.     }
  227.     break;
  228.   }
  229.   return R_NORMAL;
  230. }
  231.